package com.zys.background.common.regex;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * @author zys
 * @apiNote 正则表达的常量类
 * @since 2022-10-29
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RegexPattern {

  /**
   * 手机的正则表达式
   */
  public static final String PHONE_REGEX = "^[1](([3][0-9])|([4][0,1,4-9])|([5][0-3,5-9])|([6][2,5,6,7])|([7][0-8])|([8][0-9])|([9][0-3,5-9]))[0-9]{8}$";

  /**
   * 闰年
   */
  private static final String LEAP_YEAR = "^(\\d{2}([0248][048]|[13579][26]))";
  /**
   * 平年
   */
  private static final String NO_LEAP_YEAR = "^(\\d{4})";

  /**
   * 31 天的月
   */
  private static final String BIG_MONTH = "((0[13578])|(1[02]))-((0[1-9])|([12]\\d)|(3[01]))";
  /**
   * 30 天的月
   */
  private static final String SMALL_MONTH = "((0[469])|(11))-((0[1-9])|([12]\\d)|(30))";

  /**
   * 2 月 29 天
   */
  private static final String LEAP_MONTH = "(02)-((0[1-9])|([12]\\d))";
  /**
   * 2 月 28 天
   */
  private static final String NO_LEAP_MONTH = "(02)-((0[1-9])|(1\\d)|(2[0-8]))";


  public static final String DATE_REGEX = "((" +
      LEAP_YEAR + "-((" + BIG_MONTH + ")|(" + SMALL_MONTH + ")|(" + LEAP_MONTH + ")))|("
      +NO_LEAP_YEAR + "-((" + BIG_MONTH + ")|(" + SMALL_MONTH + ")|(" + NO_LEAP_MONTH + ")))"
      + ")";
}
